import sun.management.counter.StringCounter;
import java.util.Arrays;

class Student{
    public int a;
    public String name;


}

public class test {


    public static void main(String[] args) {
        Student s = new Student();
    }
    // 二维数组
    public static void main9(String[] args) {
        int[][] array = new int[][]{{1,2,3},{4,5,6}};
        int[][] array1 = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][3];

        int[][] array3 = new int[2][];
        array3[0] = new int[]{1,2};
        array3[1] = new int[]{1,2,3};
        System.out.println(array3[0]);
        System.out.println(array3[1]);

        for(int i = 0;i < array3.length;i++){
            for(int j = 0;j < array3[i].length;j++){
                System.out.print(array3[i][j] + " ");
            }
            System.out.println();
        }

       /* System.out.println(Arrays.deepToString(array1));
        System.out.println();*/

        /* for(int[] arr : array1){
            for(int x : arr){
                System.out.print(x + " ");
            }
            System.out.println();
        }

        System.out.println(array);
        System.out.println(array1);

        int[] array3 = new int[]{1,2,3};
        System.out.println(array3);*/
    }

    public static void main8(String[] args) {
        int[] array = {1,2,3,4,0,6};
        System.out.println(Arrays.equals(array,array));
        System.out.println(Arrays.binarySearch(array,2));
        // Arrays.sort(array);
        // System.out.println(Arrays.toString(array));
        // int[] copy = Arrays.copyOf(array,array.length * 2);
        // System.out.println(Arrays.toString(copy));
    }

    public static int[] func8(int[] array){
        Arrays.fill(array,9);
        System.out.println(Arrays.toString(array));
        return array;
    }

    public static void main7(String[] args) {
        int[] array = new int[10];
        func8(array);
    }
    public static int func7(int[] array){
        Arrays.sort(array);
        return array[array.length/ 2];
    }

    public static void main6(String[] args) {
        int[] array = {1,1,1,0,3};
        System.out.println(func7(array));
    }
    // 5. 找单生狗
    public static int func6(int[] array){
        int ret = 0;
        for(int i = 0;i < array.length;i++){
            ret ^= array[i];
        }

        return ret;
    }

    public static void main5(String[] args) {
        int[] array = {1,1,3,5,5};
        System.out.println(func6(array));
    }

    public static int[] func5(int[] array,int target){
        int n = array.length;
        // int[] a = {-1,-1};
        // int flag = 0;
        for(int i = 0;i < n;i++){
            for(int j = i+1;j < n;j++){
               if(array[i] + array[j] == target){
                   /*a[0] = i;
                   a[1] = j;
                   flag = 1;*/
                   return new int[]{i,j};
               }
            }
            // if(flag == 1) break;
        }

       // return a;
        return new int[]{-1,-1};
    }

    // 4. 找到和为target的目标的两个数
    public static void main4(String[] args) {
        int[] array = {1,2,3,6};
        int[] ret = func5(array,7);
        System.out.println(Arrays.toString(ret));
    }
    public static int binarySearch(int[] array,int key){
        int i = 0,j = array.length - 1;
        while(i <= j){
            int mid = (i + j) / 2;
            if(array[mid] > key){
                j = mid - 1;
            }
            else if(array[mid] < key){
                i = mid + 1;
            }
            else{
                return mid;
            }
        }
        return -1;
    }
    // 3. 二分查找
    public static void main3(String[] args) {
       int[] array = {2,4,6,8,10};
        /*System.out.println(binarySearch(array,2));
        System.out.println(binarySearch(array,4));
        System.out.println(binarySearch(array,5));*/

        System.out.println(Arrays.binarySearch(array,10));

    }
    public static void func3(int[] array){
        int i = 0,j = array.length - 1;
        while(i < j){
            while(i < j && array[i] % 2 != 0){
                i++;
            }
            // 现在i下标是偶数
            while(i < j && array[j] % 2 == 0){
                j--;
            }
            // 现在j下标是奇数
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }
    // 2.奇数位于偶数之前
    public static void main2(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6};
        System.out.println(Arrays.toString(array));
        func3(array);
        System.out.println(Arrays.toString(array));
    }
    // 1. 汉诺塔
    public static void move(char a,char b){
        System.out.print(a + "->" + b + " ");
    }
    public static void hanio(int n,char pos1,char pos2,char pos3){
        if(n == 1){
            move(pos1,pos3);
            return;
        }

        hanio(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanio(n-1,pos2,pos1,pos3);
    }
    public static void main1(String[] args) {
        hanio(1,'A','B','C');
        System.out.println();
        hanio(2,'A','B','C');
        System.out.println();
        hanio(3,'A','B','C');
        System.out.println();
    }
}
